var t = require("../../../@babel/runtime/helpers/interopRequireDefault"), a = require("../../../@babel/runtime/helpers/objectSpread2"), e = t(require("../../../dist/dialog/dialog")), i = require("../mixins"), s = getApp();

Page({
    behaviors: [ i ],
    data: {
        integral: "",
        active: 0,
        active1: 0,
        show: !1,
        show1: !1,
        contentRule: "",
        checked: !1,
        imagelist: [],
        activity_list: [],
        listData: [],
        count: "",
        page: 1,
        last_page: 1,
        info: {},
        love_name: "",
        integral_name: "",
        within_time: !1,
        point_name: "",
        width: 0,
        currentTime: Date.parse(new Date()) / 1e3,
        activity_id: "",
        stage_status: "",
        _arr: [],
        loading: !1,
        integral_switch: !1,
        point_switch: !1,
        point_integral: !1,
        integral_deduction: !1,
        is_privilege: 1,
        integral_pay: 0
    },
    onLoad: function(t) {
        var a = this;
        if (t.scene) {
            var e = decodeURIComponent(t.scene);
            if (e) {
                var i = [];
                i = e.split(",");
                for (var s = 0; s < i.length; s++) {
                    var n;
                    "category_id" == (n = i[s].split("="))[0] && this.setData({
                        category_id: n[1]
                    });
                }
            }
        }
        this.getDataCategory();
        var r = wx.createSelectorQuery();
        r.select(".subscribe").boundingClientRect(function(t) {
            var e = t.width;
            a.setData({
                width: e
            });
        }), r.exec();
    },
    link_poor: function() {
        wx.navigateTo({
            url: "/packageI/poor_reward/poor_reward"
        });
    },
    change_switch: function(t) {
        var a = t.currentTarget.dataset.type, e = t.detail;
        this.data.integral_switch && this.data.point_switch ? ("integral" == a ? e && this.data.point_integral ? this.setData({
            integral_deduction: e,
            point_integral: !e
        }) : this.setData({
            integral_deduction: e
        }) : "points" == a && (e && this.data.integral_deduction ? this.setData({
            integral_deduction: !e,
            point_integral: e
        }) : this.setData({
            point_integral: e
        })), this.data.point_integral || this.data.integral_deduction || s.tips("必须选择".concat(this.data.point_name, "或").concat(this.data.integral_name, "其中一种抵扣类型"))) : "integral" == a ? this.setData({
            integral_deduction: e
        }) : "points" == a && this.setData({
            point_integral: e
        }), this.get_ready();
    },
    onChangeTime: function(t) {
        this.data._arr[t.target.dataset.id] = a(a({}, t.detail), {}, {
            id: t.target.dataset.id
        }), this.setData({
            timeData: this.data._arr
        });
    },
    link: function(t) {
        var a = t.currentTarget.dataset.url;
        a && wx.navigateTo({
            url: a
        });
    },
    activeInfo: function(t) {
        var a = t.detail, e = a.data.stage_slot || [], i = a.data.stage_list.data || [], s = a.activity_id, n = a.stage_status;
        this.setData({
            love_name: a.data.love_name || "爱心值",
            point_name: a.data.point_name || "积分",
            integral_name: a.data.integral_name || "消费积分",
            page: a.data.stage_list.current_page,
            last_page: a.data.stage_list.last_page,
            active: a.active,
            status_list: e,
            listData: i,
            activity_id: s,
            stage_status: n
        });
    },
    getDataCategory: function() {
        var t = this;
        s._postNetWork({
            url: s.getNetAddresss("plugin.subscription.frontend.modules.category.controllers.page.index"),
            data: {
                category_id: this.data.category_id
            },
            success: function(a) {
                if (a.data.result) {
                    var e = a.data.data;
                    t.setData({
                        show1: !e.is_signed,
                        activity_list: e.activity_list,
                        imagelist: e.banner_list
                    }), e.is_signed || t.getRule();
                } else 0 == a.data.result && t.getData();
            }
        });
    },
    getData: function() {
        var t = this;
        s._postNetWork({
            url: s.getNetAddresss("plugin.subscription.frontend.modules.activity.controllers.page.index"),
            success: function(a) {
                if (a.data.result) {
                    var e = a.data.data;
                    t.setData({
                        show1: !e.is_signed,
                        activity_list: e.activity_list,
                        imagelist: e.banner_list
                    }), e.is_signed || t.getRule();
                } else s.tips(a.data.msg);
            }
        });
    },
    getRule: function() {
        var t = this;
        s._postNetWork({
            url: s.getNetAddresss("plugin.subscription.frontend.modules.treaty.controllers.content.index"),
            success: function(a) {
                a.data.result ? t.setData({
                    contentRule: a.data.data.content
                }) : s.tips(a.data.msg);
            }
        });
    },
    setShow: function() {
        this.setData({
            show: !this.data.show
        });
    },
    onChangePay: function(t) {
        this.setData({
            count: t.detail.value
        }), this.get_ready();
    },
    get_ready: function() {
        var t = this;
        s._postNetWork({
            url: s.getNetAddresss("plugin.subscription.frontend.modules.stage.controllers.buy.ready"),
            data: {
                stage_id: this.data.info.id,
                quantity: this.data.count
            },
            success: function(a) {
                if (1 == a.data.result) {
                    var e = a.data.data, i = e.integral_pay, s = e.point_switch, n = e.integral_switch, r = e.is_privilege, o = e.love_pay, d = e.point_pay;
                    t.setData({
                        point_switch: 0 != s,
                        integral_switch: 0 != n,
                        is_privilege: r,
                        integral_pay: i,
                        love_pay: o,
                        point_pay: d
                    });
                }
            }
        });
    },
    onClose: function() {
        this.setData({
            show: !1,
            count: "",
            love_pay: 0,
            integral_pay: 0,
            point_pay: 0,
            point_integral: !1,
            integral_deduction: !1
        });
    },
    confirm: function() {
        var t = this;
        this.setData({
            loading: !0
        });
        var a = {
            stage_id: this.data.info.id,
            quantity: this.data.count
        };
        2 == this.data.is_privilege && (this.data.point_integral ? a.privilege_type = "point" : this.data.integral_deduction ? a.privilege_type = "integral" : a.privilege_type = ""), 
        s._postNetWork({
            url: s.getNetAddresss("plugin.subscription.frontend.modules.stage.controllers.buy.generate"),
            data: a,
            success: function(a) {
                t.setData({
                    loading: !1
                }), a.data.result ? e.default.alert({
                    message: a.data.msg
                }).then(function() {
                    t.setData({
                        show: !1,
                        count: "",
                        love_pay: 0,
                        point_pay: 0,
                        integral_pay: 0
                    }), t.getActiveData();
                }) : e.default.alert({
                    message: a.data.msg
                }).then(function() {});
            }
        });
    },
    tosubscribe: function(t) {
        var a = this, e = t.currentTarget.dataset.info;
        s._postNetWork({
            url: s.getNetAddresss("plugin.subscription.frontend.modules.stage.controllers.buy.ready"),
            data: {
                stage_id: e.id,
                quantity: 1
            },
            success: function(t) {
                if (1 == t.data.result) {
                    var i = t.data.data, s = i.point_switch, n = i.integral_switch, r = i.is_privilege, o = i.integral_pay;
                    a.setData({
                        point_switch: 0 != s,
                        integral_switch: 0 != n,
                        integral_pay: o,
                        is_privilege: r,
                        show: !a.data.show,
                        info: e
                    });
                }
            }
        });
    },
    onChange: function() {
        this.setData({
            checked: !this.data.checked
        });
    },
    closeShow1: function() {
        var t = this;
        if (!this.data.checked) return wx.showToast({
            title: "请勾选协议",
            icon: "none"
        });
        s._postNetWork({
            url: s.getNetAddresss("plugin.subscription.frontend.modules.treaty.controllers.agree.index"),
            success: function(a) {
                a.data.result && (s.tips(a.data.msg), t.setData({
                    show1: !1
                }));
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    getActiveData: function() {
        var t = this;
        s._postNetWork({
            url: s.getNetAddresss("plugin.subscription.frontend.modules.activity.controllers.detail.index"),
            data: {
                activity_id: this.data.activity_id,
                stage_status: this.data.stage_status,
                page: 1
            },
            success: function(a) {
                if (a.data.result) {
                    var e = a.data.data, i = e.stage_slot || [], n = e.stage_list.data || [];
                    t.setData({
                        page: e.stage_list.current_page,
                        last_page: e.stage_list.last_page,
                        status_list: i,
                        listData: n
                    });
                } else s.tips(a.data.msg);
            }
        });
    },
    onReachBottom: function() {
        var t = this;
        if (this.data.page >= this.data.last_page) return !1;
        s._postNetWork({
            url: s.getNetAddresss("plugin.subscription.frontend.modules.activity.controllers.detail.index"),
            data: {
                activity_id: this.data.activity_id,
                stage_status: this.data.stage_status,
                page: page
            },
            success: function(a) {
                if (a.data.result) {
                    var e = a.data.data;
                    t.setData({
                        show1: !e.is_signed,
                        activity_list: t.data.activity_list.concat(e.activity_list),
                        imagelist: e.banner_list
                    });
                } else s.tips(a.data.msg);
            }
        });
    },
    onShareAppMessage: function() {}
});